<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProjectMadaktariMVC.Models.Episode>" %>



<% using (Html.BeginForm())
    using(var db = ProjectMadaktariMVC.Models.DBFactory.CreateContext())
       { %>
<div id="episodeForm">
    
    <ul>
        <li><a href="#Admit">Admit</a></li>
        <li><a href="#Procedure">Procedure</a></li>
        <li><a href="#Discharge">Discharge</a></li>
        <li><a href="#FollowUp">Follow Up</a></li>
    </ul>
    
    <div id="Admit">
        <input type="submit" value="Save" onclick="$('#tabField').val('Admit')"/>
        <input type="hidden" name="tab" id="tabField" value="" />
        <% if (Model.Id != 0)
           {%>
            <%=Html.ActionLink("Cancel", "ViewEpisode", "Patient", null, null, "Admit", new {EpisodeId = Model.Id, PatientId = ViewData["PatientId"]}, null) %>
        <%}
           else
           { %>
            <%=Html.ActionLink("Cancel", "View","Patient", null, null, "Admit",  new {id = ViewData["PatientId"]}, null) %>
        <%} %>
        <div class="form_block">
            <span class="form_label"><label for="AdmitDate">Admit Date</label></span>
            <%= Html.TextBox("AdmitDate", Model.AdmitDate == null ? "" : ((DateTime)Model.AdmitDate).ToString("MM/dd/yyyy"), new { @class = "datefield" })%>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="HospitalId">Hospital</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.HospitalDropDown(db, "HospitalId", Model.HospitalId) %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="ReferralLocationID">Referral Location</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.referralLocationDropdown(db, "ReferralLocationID", Model.ReferralLocationId) %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="Diagnoses">Diagnosis</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.DiagnosisList(db, "Diagnoses", Model.Id) %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="diagnosisOther">Diagnosis Other</label></span>
            <%= Html.TextArea("diagnosisOther", Model.DiagnosisOther, new { cols = "45", rows = "5" })%>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label"><label for="ConcomitantDiagnosis1Id">Concomitant Diagnosis</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.ConcomitantDiagnosisDropDown(db, "ConcomitantDiagnosis1Id" , Model.ConcomitantDiagnosisId1) %><br /><br />
        
            <span class="form_label"><label for="ConcomitantDiagnosis2Id"><br /></label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.ConcomitantDiagnosisDropDown(db, "ConcomitantDiagnosis2Id" , Model.ConcomitantDiagnosisId2) %>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label"><label for="surgicalHistory">Surgical History</label></span>
            <%= Html.TextArea("surgicalHistory", Model.SurgicalHistory, new { cols = "45", rows = "5" })%>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label"><label for="caseComments">Case Comments</label></span>
            <%= Html.TextArea("caseComments", Model.CaseComments, new { cols="45", rows="5"}) %>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label"><label for="imageFindings">Image Findings</label></span>
            <%= Html.TextArea("imageFindings",Model.ImageFindings, new {cols="45", rows="5"}) %>
        </div>
        <input type="submit" value="Save" onclick="$('#tabField').val('Admit')"/>
        <% if (Model.Id != 0)
           {%>
            <%=Html.ActionLink("Cancel", "ViewEpisode", "Patient", null, null, "Admit", new {EpisodeId = Model.Id, PatientId = ViewData["PatientId"]}, null) %>
        <%}
           else
           { %>
            <%=Html.ActionLink("Cancel", "View","Patient", null, null, "Admit",  new {id = ViewData["PatientId"]}, null) %>
        <%} %>
    </div>
    
    <div id="Procedure">
        <em>Please save episode before adding or editing procedures.</em>
    </div>
    
    <div id="Discharge">
        <input type="submit" value="Save" onclick="$('#tabField').val('Discharge')"/>
        <% if (Model.Id != 0)
           {%>
            <%=Html.ActionLink("Cancel", "ViewEpisode", "Patient", null, null, "Discharge", new {EpisodeId = Model.Id, PatientId = ViewData["PatientId"]}, null) %>
        <%}
           else
           { %>
            <%=Html.ActionLink("Cancel", "View","Patient", null, null, "Discharge",  new {id = ViewData["PatientId"]}, null) %>
        <%} %>
        <div class="form_block">
            <span class="form_label"><label for="DischargeDate">Discharge Date</label></span>
            <%= Html.TextBox("dischargeDate", Model.DischargeDate == null ? "" : ((DateTime)Model.DischargeDate).ToString("MM/dd/yyyy"), new {@class="datefield"}) %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="PostOpStatus">Post-Op Status</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.PostOpStatusDropDown(db, "PostOpStatus", Model.PostOpStatus)%>
        </div>
        
        <div class="form_block">
            <span class="form_label">Days Post Op</span>
            <% if (Model.DischargeDate == null)
               { %>
                <em>number of days will be automatically calculated</em>
            <%}
               else
               { %>
                <%= (DateTime.Today - (DateTime)Model.DischargeDate).Days%> Days
            <%} %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="complications">Post-Op Complications</label></span>
            <%= ProjectMadaktariMVC.Helpers.ConfigurationHelper.ComplicationsRadioButtons("complications", Model.Complications) %>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label"><label for="complicationsNotes">Complications Notes</label></span>
            <%= Html.TextArea("complicationsNotes", Model.ComplicationNotes, new {cols="45", rows="5"}) %>
        </div>
        <br />
        <div class="form_block">
            <span class="form_label">Length of Stay</span>
            <% if (Model.AdmitDate == null || Model.DischargeDate == null)
               {%>
                <em>length of stay will be automatically calculated</em>
            <%}
               else
               { %>
                <%= ((DateTime)Model.DischargeDate - (DateTime)Model.AdmitDate).Days %> Days
            <%} %>
        </div>
        <input type="submit" value="Save" onclick="$('#tabField').val('Discharge')"/>
        <% if (Model.Id != 0)
           {%>
            <%=Html.ActionLink("Cancel", "ViewEpisode", "Patient", null, null, "Discharge", new {EpisodeId = Model.Id, PatientId = ViewData["PatientId"]}, null) %>
        <%}
           else
           { %>
            <%=Html.ActionLink("Cancel", "View","Patient", null, null, "Discharge",  new {id = ViewData["PatientId"]}, null) %>
        <%} %>
    </div>
    
    <div id="FollowUp">
        <input type="submit" value="Save" onclick="$('#tabField').val('FollowUp')"/>
        <% if (Model.Id != 0)
           {%>
            <%=Html.ActionLink("Cancel", "ViewEpisode", "Patient", null, null, "FollowUp", new {EpisodeId = Model.Id, PatientId = ViewData["PatientId"]}, null) %>
        <%}
           else
           { %>
            <%=Html.ActionLink("Cancel", "View","Patient", null, null, "FollowUp",  new {id = ViewData["PatientId"]}, null) %>
        <%} %>
        <div class="form_block">
            <span class="form_label"><label for="followUpDate">Date of Follow-Up</label></span>
            <%= Html.TextBox("followUpDate", Model.FollowUpDate == null ? "" : ((DateTime)Model.FollowUpDate).ToString("MM/dd/yyyy"), new {@class="datefield"}) %>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="followUpStatus">Follow-Up Status</label></span>
            <%= Html.TextArea("followUpStatus", Model.FollowUpStatus, new { cols = "45", rows = "5" })%>
        </div>
        
        <div class="form_block">
            <span class="form_label"><label for="followUpImaging">Follow-Up Imaging</label></span>
            <%= Html.TextArea("followUpImaging", Model.FollowUpImaging, new { cols = "45", rows = "5" })%>
        </div>
    </div>
    
    <%} %>
    
</div>

<script type="text/javascript">
    $(function() {
        var $tabs = $("#episodeForm").tabs();
        //        if ($tabs.tabs('option', 'selected') == 1){
        //            load: function(event, ui) {
        //                $('a', ui.panel).click(function() {
        //                    $(ui.panel).load(this.href);
        //                    return false;
        //                });
        //            }
        //        }

        $(".datefield").datepicker();
        $("#procedureList").accordion({ active: false, collapsible: true, autoHeight: false });
    });

</script>
